package com.atxwq.shop.manager.controller;

import com.atxwq.shop.manager.serivce.BrandService;
import com.atxwq.shop.model.entity.product.Brand;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 分类管理
 * @Date 2025/5/13 14:15
 * @Created by 12336
 */

@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 分页查询品牌
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit){
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加品牌
     * @param brand
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改品牌
     * @param brand
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Long id){
        brandService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
/*========================================================================================================*/

    /**
     * 注意以下是分类品牌页面功能
     * 查询所有品牌
     * @return
     */
    @GetMapping("findAllBrand")
    public Result findAllBrand(){
        List<Brand> list = brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


}
